package com.maridress.maridress.presenter;

import com.maridress.maridress.common.base.BasePresenter;
import com.maridress.maridress.model.HttpResult;
import com.maridress.maridress.model.UserResponse;
import com.maridress.maridress.service.intf.UserViewInterface;

import java.util.List;

import rx.Observer;

/**
 * Created by tenmei on 16/9/7.
 */
public class UserPresenter extends BasePresenter implements Observer<HttpResult<List<UserResponse>>> {

    private UserViewInterface mViewInterface;

    public UserPresenter(UserViewInterface viewInterface) {
        mViewInterface = viewInterface;
    }

    @Override
    public void onCompleted() {
        mViewInterface.onCompleted();
    }

    @Override
    public void onError(Throwable e) {
        mViewInterface.onError(e.getMessage());
    }

    @Override
    public void onNext(HttpResult<List<UserResponse>> userResponseHttpResult) {
        mViewInterface.onUser(userResponseHttpResult);
    }

    public void getUserInfo() {
        unSubscribeAll();
        subscribe(mViewInterface.getUserInfo(), UserPresenter.this);
    }
}
